<?php
class M_DbTable_Region extends Apps_Db_Table_Abstract {
	protected $_name = 'region';

	const STATUS_ACTIVE 	= 1;
	const STATUS_INACTIVE 	= 0;
	const STATUS_DELETED 	= -1;

	//LIST
	public function getList () {
		$q = $this->_db
				  ->select()
				  ->from(array('r' => $this->_name), null)
				  ->join(array('c' => 'country'), 'r.country_id = c.id', null)
				  ->joinLeft(array('a' => 'area'), 'a.id = r.area_id', null)
				  ->where('r.status =?', self::STATUS_ACTIVE)
				  ->columns(array('id'			=> 'r.id',
				 				  'name'		=> 'r.name',
				 				  'en_name'		=> 'r.en_name',
				 				  'country_name'=> 'c.en_name',
				 				  'area_name'	=> 'a.en_name',
				 				  'description'	=> 'r.description',
				  				  'created_date'=> 'r.created_date'));
 		return $q;
	}

	public function listRegionByCountryId ($countryId) {
		$q = $this->_db
				  ->select()
				  ->from(array('r' => $this->_name), null)
				  ->join(array('c' => 'country'), 'r.country_id = c.id', null)
				  ->where('r.status =?', self::STATUS_ACTIVE)
				  ->where('c.id =?', $countryId)
				  ->columns(array('id'			=> 'r.id',
				 				  'name'		=> 'r.name',
				 				  'en_name'		=> 'r.en_name',
				 				  'country_name'=> 'c.en_name',
				 				  'description'	=> 'r.description',
				  				  'created_date'=> 'r.created_date'));
 		return $q;
	}
}